using System;
using flickr.api;

namespace FlickrShots.Framework
{
	public abstract class PhotoStream
	{
        private PhotoCollection _photostream;

        public Photo this[int index]
        {
            get { return Stream[index]; }
        }

	    public int Count
	    {
	        get { return Stream.Count; }
	    }

        private PhotoCollection Stream
        {
            get
            {
                if (_photostream == null)
                {
                    _photostream = GetPhotoCollection();
                }
                return _photostream;
            }
        }

        public override string ToString()
        {
            return "Photostream";
        }

        public override bool Equals(object obj)
        {
            PhotoStream ps = obj as PhotoStream;
            if (ps == null)
                return false;

            return ps.ToString() == ToString();
        }

        public override int GetHashCode()
        {
            return ToString().GetHashCode();
        }
	    
		protected abstract PhotoCollection GetPhotoCollection();
	}

	public class UsersPhotoStream : PhotoStream
	{
        private User _user;
        public UsersPhotoStream(string userName)
        {
            _user = new User(Flickr.People.findByUsername(userName));
        }

		protected override PhotoCollection GetPhotoCollection()
		{
            return Flickr.People.getPublicPhotos(_user.ID).PhotoCollection;
		}

        public override string ToString()
        {
            return "My " + base.ToString();
        }
	}

	public class EveryonesPhotoStream : PhotoStream
	{
		protected override PhotoCollection GetPhotoCollection()
		{
            return Flickr.Photos.getRecent().PhotoCollection;
        }

        public override string ToString()
        {
            return "Everyone's " + base.ToString();
        }
	}

	public class FriendsPhotoStream : PhotoStream 
	{
		protected override PhotoCollection GetPhotoCollection()
		{
            return Flickr.Photos.getContactsPhotos().PhotoCollection;
		}

        public override string ToString()
        {
            return "My Friends' " + base.ToString();
        }
	}
    
    public class TagPhotoStream : PhotoStream
    {
        private string[] _tags;
        public TagPhotoStream(string[] tags)
        {
            _tags = tags;
        }
        protected override PhotoCollection GetPhotoCollection()
        {
            return Flickr.Photos.search(null, _tags, TagMode.Any, null, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MaxValue, null, null, PrivateFilter.Public, PhotoSearchExtras.None, int.MinValue, int.MinValue).PhotoCollection;
        }
    }
}
